package cn.remex.web.service;

import cn.remex.RemexConstants.ResponseContentType;
import cn.remex.core.exception.ServiceCode;
import cn.remex.db.rsql.sqlutil.ReslutList;

import java.io.Serializable;

/**
 * 业务服务结果装配返回
 */
public class BsRvo implements Serializable{
	private static final long serialVersionUID = 4613569092879127908L;
	private String callback;//完成响应后需要处理的事情
	private String msg;
	private String code = ServiceCode.FAIL;
	private Object body;

	/*
	 *	是否只输出body，而不输出BsRvo结构，一般用于对外接口，BsRvo结构不能满足对外要求的返回结构时使用
	 *  要求：body必须为String为key的map
	 *  add by lixin 2018-01-04
	 */
	private boolean bodyOutputOnly = false;

	private ResponseContentType responseContentType; //jsp json redirect text 四种 contentType
	private String responseHandelParam;

	public BsRvo(){}

	public BsRvo(boolean bodyOnly, Object body){
		this.bodyOutputOnly = bodyOnly;
		this.body = body;
	}

	public BsRvo(String code, String msg) {
		this.msg = msg;
		this.code = code;
	}
	public BsRvo(String code, String msg, Object body) {
		this.msg = msg;
		this.code = code;
		this.body = body;

		if(null!= body && body instanceof ReslutList){
			//此接口适用于数据rowMap响应的数据，需要通过RMX.evalWhole将扁平化数据展开为json结构
			//前端BusinessService实现了这个逻辑
			callback = "EVAL_RESPONSE_BODY";
		}
	}

	/*
	 * @param responseContentType jsp json redirect text 四种 contentType
	 */
	public BsRvo(String code, String msg, Object body, ResponseContentType responseContentType, String responseHandelParam) {
		this.msg = msg;
		this.code = code;
		this.body = body;
		this.responseHandelParam = responseHandelParam;
		this.responseContentType = responseContentType;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public Object getBody() {
		return body;
	}

	public void setBody(Object body) {
		this.body = body;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getResponseHandelParam() {
		return responseHandelParam;
	}

	public void setResponseHandelParam(String responseHandelParam) {
		this.responseHandelParam = responseHandelParam;
	}

	public ResponseContentType getResponseContentType() {
		return responseContentType;
	}

	public void setResponseContentType(ResponseContentType responseContentType) {
		this.responseContentType = responseContentType;
	}

	public String getCallback() {
		return callback;
	}

	public void setCallback(String callback) {
		this.callback = callback;
	}

	public boolean bodyOnly(){
		return this.bodyOutputOnly;
	}
}
